package com.jingdianjichi.subject.domain.handler.subject;

import com.jingdianjichi.subject.common.enums.IsDeletdFlageEnum;
import com.jingdianjichi.subject.common.enums.SubjectInfoEnum;
import com.jingdianjichi.subject.domain.convert.SubjectBriefConverter;
import com.jingdianjichi.subject.domain.entity.SubjectAnswerBO;
import com.jingdianjichi.subject.domain.entity.SubjectInfoBO;
import com.jingdianjichi.subject.infra.basic.entity.SubjectBrief;
import com.jingdianjichi.subject.infra.basic.service.SubjectBriefService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * SubjectRadioHandler 类
 *
 * @author 熊苏鹏1
 * @date 2025/2/20 21:06
 * @description 单选策略
 */
@Component
public class SubjectBriefHandler implements SubjectTypeHandler{
    @Resource
    private SubjectBriefService subjectBriefService;
    @Override
    public SubjectInfoEnum getSubjectType() {
        return SubjectInfoEnum.BRIEF;
    }

    @Override
    public void add(SubjectInfoBO subjectInfoBO) {
        List<SubjectBrief> subjectBriefList = new ArrayList<>();
            SubjectBrief subjectBrief = SubjectBriefConverter.INSTANCE.convertBoToEntity(subjectInfoBO);
            subjectBrief.setSubjectId(Math.toIntExact(subjectInfoBO.getId()));
            subjectBrief.setIsDeleted(IsDeletdFlageEnum.NOT_DELETED.getCode());
        subjectBriefService.insert(subjectBrief);

    }

    @Override
    public SubjectAnswerBO query(SubjectInfoBO subjectInfoBO) {
        SubjectBrief subjectBrief = subjectBriefService.query((long) subjectInfoBO.getId());
        SubjectAnswerBO subjectAnswerBO = new SubjectAnswerBO();
        subjectAnswerBO.setSubjectAnswer(subjectBrief.getSubjectAnswer());
        return subjectAnswerBO;
    }
}
